package com.situ.fly.controller.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.situ.fly.entity.JSONResult;
import com.situ.fly.entity.SignStatus;
import com.situ.fly.entity.User;
import com.situ.fly.service.SignService;

@RestController
@RequestMapping("/api/sign/")
public class APISignController {

	@Autowired
	private SignService signService;

	@PostMapping("/in")
	public JSONResult in(HttpSession session) {

		User user = (User) session.getAttribute("user");
		SignStatus signStatus = signService.sign(user);

		JSONResult json = new JSONResult();
		json.setData(signStatus);

		return json;
	}

	@PostMapping("/status")
	public JSONResult status(HttpSession session) {

		User user = (User) session.getAttribute("user");

		SignStatus signStatus = signService.getSignStatus(user);

		JSONResult json = new JSONResult();
		json.setData(signStatus);

		return json;
	}

	@PostMapping("/ranking")
	public JSONResult ranking() {

		List newRanking = signService.getNewRanking();
		List fastRanking = signService.getFastRanking();
		List totalRanking = signService.getTotalRanking();

		JSONResult json = new JSONResult();
		json.setData(new Object[] {newRanking, fastRanking, totalRanking});

		return json;
	}
}
